from xml.dom.minidom import parse
import configparser


# 这是用来读取conf文件下的IPconfig文件的配置读取类
class Get_Cluster_Ip_By_Conf:
    def __init__(self):
        self.__path = "../conf/ipconfig.xml"
        self.__Tree = parse(open(self.__path))
        self.__Clusterslist = self.__Tree.documentElement
        self.__Clusters = self.__Clusterslist.getElementsByTagName("cluster")

        self.__val = []

    def Get_host(self):
        for Cluster in self.__Clusters:
            self.__val.append([Cluster.childNodes[1].firstChild.nodeValue,
                               Cluster.childNodes[3].firstChild.nodeValue,
                               Cluster.childNodes[5].firstChild.nodeValue,
                               Cluster.childNodes[7].firstChild.nodeValue])  # 1代表IP， 3代表post
        return self.__val


class Get_globleconfig:
    def __init__(self):
        self.__inipath = '../conf/globalconfig.ini'
        self.__confini = configparser.ConfigParser()
        self.__confini.read(self.__inipath)

        self.val = None

    def Get_setting(self, title, tab):
        self.val = self.__confini.get(title, tab)

        return self.val
